import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
export const useAuthStore = defineStore('auth', () => {
    const token = ref('')
    const user = ref({
    })
    const isLoggedIn = computed(() => {
        return token.value !== ''
    })
    const setUser = (newUser) => {
        user.value = newUser
    }
    const setToken = (newToken) => {
        token.value = newToken
    }
    const clear = () => {
        token.value = ''
        user.value = {}
    }

    return { token, setToken, user, setUser, clear, isLoggedIn }
}, {
    persist: true
})